package com.jinsi.controller.lv;


import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @Description TODO
 * @ClassName UserController
 * @Content 用户控制层
 * @Author 吕昊燃
 * @Date 2022/9/14 8:43
 */
@Controller
@Slf4j
public class UserController {

    @RequestMapping("/index")
    public String showHome() {
        String name = SecurityContextHolder.getContext().getAuthentication().getName();
        log.info("当前登录用户,name:{}",name);
//        System.out.println(SecurityContextHolder.getContext().getAuthentication());
        return "redirect:pages/index/index.html";
    }

    @RequestMapping("/login1")
    public String showLogin() {
        log.info("进入登陆页");
        return "login.html";
    }

    @RequestMapping("/admin")
    @ResponseBody
    @PreAuthorize("hasRole('ROLE_ADMIN')")
    public String printAdmin() {
        return "如果你看见这句话，说明你有ROLE_ADMIN角色";
    }

    @RequestMapping("/user")
    @ResponseBody
    @PreAuthorize("hasRole('ROLE_USER')")
    public String printUser() {
        return "如果你看见这句话，说明你有ROLE_USER角色";
    }

}
